<?php if ($error != ''): ?>
    <ul class="message error">
        <?php if ($error != ''): ?>
            <li><?php echo $error ?></li>
        <?php endif; ?>
        <?php echo form_error('name') ?>
        <?php echo form_error('url') ?>
        <?php echo form_error('upload') ?>
        <?php echo form_error('width') ?>
        <?php echo form_error('height') ?>
    </ul>
<?php endif; ?>
<form class="form has-validation" method="POST" action="" style="width: 600px;float:left">
    <input type="hidden" name="frmToken" id="frmToken" value="<?php echo $frmToken ?>"/>
    <div class="clearfix">
        <label for="form-name" class="form-label">Tên quảng cáo<em>*</em><small>Nhập tên quảng cáo</small></label>
        <div class="form-input"><input type="text" id="form-name" name="name" value="<?php echo $all[0]['name']?>" required="required" /></div>
    </div>
    <div class="clearfix">
        <label for="form-upload" class="form-label">Ảnh quảng cáo</label>
        <div class="form-input">
            <input type="text" id="form-upload" name="upload" value="<?php echo $all[0]['img']?>" required="required"/></div>
    </div>
    <div class="clearfix">
        <label for="form-url" class="form-label">Địa chỉ liên kết<em>*</em><small>Nhập địa chỉ liên kết</small></label>
        <div class="form-input"><input type="text"  id="form-url" name="url" required="required" value="<?php echo $all[0]['href']?>" /></div>
    </div>
    <div class="clearfix">
        <label for="form-url" class="form-label">Độ rộng quảng cáo<em>*</em><small>Nhập độ rộng(tối đa 174px)</small></label>
        <div class="form-input"><input type="text"  id="form-width" name="width" onkeypress="return keypress(event);" value="<?php echo $all[0]['width']?>" required="required" /></div>
    </div>
    <div class="clearfix">
        <label for="form-url" class="form-label">Độ cao quảng cáo<em>*</em><small>Nhập độ cao quảng cáo</small></label>
        <div class="form-input"><input type="text"  id="form-height" name="height" onkeypress="return keypress(event);" value="<?php echo $all[0]['height']?>" required="required" /></div>
    </div>

    <div class="clearfix">
        <label for="form-location" class="form-label">Vị trí quảng cáo</label>
        <div class="form-input">
            <select id="form-location" name="location" required="required">
                <?php if($all[0]['position'] == 1) { ?>
                <option value="1" selected="selected">Cột trái</option>
                <option value="2">Cột phải</option>
                <?php } else {?>
                <option value="1">Cột trái</option>
                <option value="2" selected="selected">Cột phải</option>
                <?php }?>
            </select>
        </div>
    </div>
    
    <div class="clearfix">
        <label for="form-no" class="form-label">Thứ tự</label>
        <div class="form-input">
            <select id="form-no" name="no" required="required">
                <?php for($i = 1; $i < 11; $i++) { ?>
                <option value = "<?php echo $i?>"<?php echo ($all[0]['order'] == $i)? "selected = 'selected'" : ""?> ><?php echo $i;?></option>
                <?php }?>
            </select>
        </div>
    </div>

    <div class="form-action clearfix">
        <input class="button" type="submit" name="submit" data-icon-primary="ui-icon-circle-check" value="OK"/>
        <input class="button" type="reset" value="Nhập lại"/>
    </div>
</form>
<div class="ad-preview">
    <p>Xem trước ảnh quảng cáo</p>
    <img id="img-preview" src="<?php echo STATIC_DOMAIN ?><?php echo preg_replace('/\/(.*)^$/', '$0', $all[0]['img'])?>" style="width: 290px;height:auto;margin:10px auto;display: block"/>
</div>

<script type="text/javascript">
    function initFinder() 
    {
        $("#form-upload").click(function() {
            var finder = new CKFinder( { width : 600 } ),
                obj = $(this),
                preview  = $("#img-preview");
            finder.selectActionFunction = function(fileUrl, data) {
                obj.val(fileUrl);
                preview.attr('src' , base_url + fileUrl);
            };
            finder.basePath = '/Images/';
            finder.resourceType = "Images";
            finder.popup(800,600);
        });
    }
    function keypress(e){
        var keypressed = null;
        if (window.event)
        {
            keypressed = window.event.keyCode;
        }
        else
        { 
            keypressed = e.which;
        }

        if (keypressed < 48 || keypressed > 57)
        {
            if (keypressed == 8 || keypressed == 127)
            {
                return;
            }
            return false;
        }
    }
    $(document).ready(function() {
        $('#form-price').setMask({
            mask: '999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999.99',
            type: 'reverse',
            defaultValue: '0'
        });
        initFinder();
    });
     
</script>
   